<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>父子组件传值的应用</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <counter :number="2" ref="one" @add="count"></counter>
        <counter :number="3" ref="two" @add="count"></counter>
        <div>{{total}}</div>
    </div>
</body>
<script>

    Vue.component('counter',{
        template:'<div @click="add">{{content}}</div>',
        props:{
            'number':{
                required:false
            }
        },
        data(){
            return {
               content:this.number
            }
        },
        methods: {
            add:function () {
                this.content++
                console.log(typeof this.content);
                this.$emit('add')
            }
        }
    })

    var app = new Vue({
        el:'#app',
        data:{
            total:''
        },
        // computed:{
        //   change:function () {
        //       return this.total
        //   }
        // },
        methods:{
            count: function () {
                console.log("2的"+typeof this.$refs.two.content);
                this.total = this.$refs.one.content + this.$refs.two.content
            }
        }
    })
</script>
</html>
